// @FileName  :frequency.c
// @Time      :2024/3/21 11:06
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>
#include <ctype.h>

typedef struct node {
    char val[150];
    int cnt;
    struct node *nxt;
} node;

void copy(char *dest, char *src) {
    for (int i = 0; i < strlen(src); i++)
        dest[i] = src[i];
    if (!isalpha(dest[strlen(src) - 1]))
        dest[strlen(src) - 1] = '\0';
    dest[strlen(src)] = '\0';
}

void solve() {
    freopen("article.txt", "r", stdin);
    node *head = (node *) malloc(sizeof(node)), *cur;
    head->nxt = NULL;
    char buf[1500];
    char all[500][20];
    int flag = 0, num = 0;
    while (gets(buf) != NULL) {//一行
        int cnt = 0;
        for (int i = 0; i < strlen(buf)+1; i++) {
            if (isalpha(buf[i]))
                all[num][cnt++] = isupper(buf[i]) ? tolower(buf[i]) : buf[i];
            else if (cnt != 0)
                all[num][cnt] = '\0', cnt = 0, num++;
        }
    }
    for (int i = 0; i < num; i++) {//构造链表
        if (flag == 0) {
            flag = 1;
            copy(head->val, all[i]);
            head->cnt = 1;
            head->nxt = NULL;
        } else {
            cur = head;
            if (strcmp(all[i], cur->val) < 0) {
                node *nd = (node *) malloc(sizeof(node));
                nd->cnt = 1;
                copy(nd->val, all[i]);
                nd->nxt = head;
                head = nd;
                continue;
            } else if (strcmp(all[i], cur->val) == 0) {
                cur->cnt++;
                continue;
            }
            while (strcmp(all[i], cur->val) > 0) {
                if (cur->nxt == NULL) {
                    node *nd = (node *) malloc(sizeof(node));
                    nd->cnt = 1;
                    copy(nd->val, all[i]);
                    nd->nxt = NULL;
                    cur->nxt = nd;
                    break;
                } else if (strcmp(all[i], cur->nxt->val) == 0) {
                    cur->nxt->cnt++;
                    break;
                } else if (strcmp(all[i], cur->nxt->val) < 0) {
                    node *nd = (node *) malloc(sizeof(node));
                    nd->cnt = 1;
                    copy(nd->val, all[i]);
                    nd->nxt = cur->nxt;
                    cur->nxt = nd;
                    break;
                }
                cur = cur->nxt;
            }
        }
    }
    while (head != NULL) {
        printf("%s %d\n", head->val, head->cnt);
        head = head->nxt;
    }
}
int main() {
    setbuf(stdout, 0);
    solve();
}